/*
 ------------------------------------------------------------------------------
	winmad++ -	a test program for using SDL and mad library on Windows
				with object oriented UI style
				with low level mad (seek)

	Copyright (C) 2011 Pierre Veber
	
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software Foundation,
	Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
------------------------------------------------------------------------------
*/

#include "precomp.h"

/*
 ===========================================================================
	String utils
 ===========================================================================
*/


#ifdef WIN32
char* _strndup(const char* s, size_t n)
{
	char* nu = (char*)malloc((n+1)*sizeof(char));
	if (nu == NULL)
	{
		throw "_strndup: unable to allocate memory";
	}
	strncpy(nu, s, n);
	nu[n] = '\0';
	return nu;
}
#endif

#define IS_WHITESPACE(c)	(c == ' ') || (c == '\t') || (c == '\r') || (c == '\n')
char* _pack(char* str)
{
	char* p = str;
	while (*p != '\0')
	{
		if ( IS_WHITESPACE(*p) )
		{
			memmove(p, p+1, strlen(p+1) + 1);
		}
		else
		{
			*p = tolower(*p);
			p++;
		}
	}
	return str;
}